﻿using System.IO;
using System.Web.Mvc;

namespace YawetagLib.Web.Utilities
{
    public static class ViewProcessor
    {
        public static string GetContent(ControllerContext controllerContext, 
            string viewName, string masterName, ViewDataDictionary viewData, TempDataDictionary tempData)
        {
            using (StringWriter viewWriter = new StringWriter())
            {
                IView view = ViewEngines.Engines.FindView(controllerContext, viewName, masterName).View;
                ViewContext viewContext = new ViewContext(controllerContext, view, viewData, tempData, viewWriter);

                view.Render(viewContext, viewWriter);
                viewWriter.Flush();

                return viewWriter.ToString();
            }
        }
    }
}